home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / comps / widgets / delphi10 / gifimage / gifimage.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-18  |  2.3 KB  |  106 lines

  1. unit Gifimage;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, ExtCtrls, CCGIF;
  8.  
  9. type
  10.   TGifImage = class(TImage)
  11.   private
  12.     { Private declarations }
  13.     FTheFileName : String;
  14.     TheGif : PGif;
  15.   protected
  16.     { Protected declarations }
  17.     OldFileName : String;
  18.     TheBitmap : TBitmap;
  19.     valid_load : Boolean;
  20.   public
  21.     { Public declarations }
  22.     constructor Create( AOwner : TComponent ); override;
  23.     destructor Destroy; override;
  24.     procedure Paint; override;
  25.     procedure LoadGIFFile;
  26.   published
  27.     { Published declarations }
  28.     property TheFileName : String read FTheFileName write FTheFileName;
  29.   end;
  30.  
  31. procedure Register;
  32.  
  33. implementation
  34.  
  35. constructor TGIFImage.Create( AOwner : TComponent );
  36. begin
  37.   inherited Create( AOwner );
  38.   TheBitmap := TBitmap.Create;
  39. end;
  40.  
  41. destructor TGIFImage.Destroy;
  42. begin
  43.   TheBitmap.Free;
  44.   inherited Destroy;
  45. end;
  46.  
  47. procedure TGIFImage.LoadGIFFile;
  48. var thebuffer : array[ 0..255] of char;
  49.     TheGif : PGif;
  50. begin
  51.   Valid_Load := false;
  52.   if not FileExists( TheFileName ) then
  53.   begin
  54.     MessageDlg( TheFileName + ' cannot be found!',mterror,[mbOK],0);
  55.     exit;
  56.   end;
  57.   Screen.Cursor := crHourGlass;
  58.   StrPCopy( TheBuffer , TheFilename );
  59.   TheGif := NEW( PGif , Init( theBuffer ));
  60.   TheBitmap.Width := TheGif^.ImageDescriptor.ImageWidth;
  61.   TheBitmap.Height := TheGif^.ImageDescriptor.ImageHeight;
  62.   TheGif^.Decode( false , TheBitmap );
  63.   Dispose( TheGif , Done );
  64.   Screen.Cursor := crDefault;
  65.   oldFileName := TheFileName;
  66.   valid_load := true;
  67. end;
  68.  
  69. procedure TGIFImage.Paint;
  70. begin
  71.   if csDesigning in ComponentState then
  72.   begin
  73.     inherited Paint;
  74.     exit;
  75.   end;
  76.   if TheFileName = '' then
  77.   begin
  78.     inherited Paint;
  79.     exit;
  80.   end;
  81.   if oldfilename <> Thefilename then
  82.   begin
  83.     LoadGIFFile;
  84.     if not Valid_load then
  85.     begin
  86.       Picture.Bitmap.Height := 0;
  87.       Picture.Bitmap.Width := 0;
  88.       inherited Paint;
  89.       exit;
  90.     end;
  91.     Picture.Bitmap.Height := TheBitmap.Height;
  92.     Picture.Bitmap.Width := TheBitmap.Width;
  93.     Picture.Bitmap.Handle := TheBitmap.Handle;
  94.     inherited Paint;
  95.     exit;
  96.   end;
  97.   inherited Paint;
  98. end;
  99.  
  100. procedure Register;
  101. begin
  102.   RegisterComponents('Widgets', [TGifImage]);
  103. end;
  104.  
  105. end.
  106.